package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import com.demonsters.debugger.MonsterDebugger;
	import flash.events.KeyboardEvent;
	import flash.events.TimerEvent;
	import flash.ui.Keyboard;
	import flash.utils.Timer;
	
	/**
	 * ...
	 * @author
	 */
	
	[Frame(factoryClass="Preloader")]
	
	public class Main extends Sprite
	{
		static public const TESTING:Boolean = true; // FALSE - перед заливкой в продакшн
		static public const GAME_WIDTH:Number = 800;
		static public const GAME_HEIGHT:Number = 600;
		
		static public var _mm:MainMenu = new MainMenu();
		static public var _wr:World = new World();
		static public var m:Main;
		static public var a_pressed:Boolean;
		static public var d_pressed:Boolean;
		
		public function Main():void
		{
			if (stage)
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, on_key_down);
			stage.addEventListener(KeyboardEvent.KEY_UP, on_key_up);
			m = this;
			addChild(_mm);
			if (TESTING)
			{
				MonsterDebugger.initialize(this);
			}
		}
		
		private function on_key_up(e:KeyboardEvent):void
		{
			switch (e.keyCode)
			{
				case Keyboard.A: 
					a_pressed = false;
					break;
				case Keyboard.D: 
					d_pressed = false;
					break;
			}
		}
		
		private function on_key_down(e:KeyboardEvent):void
		{
			switch (e.keyCode)
			{
				case Keyboard.A: 
					a_pressed = true;
					break;
				case Keyboard.D: 
					d_pressed = true;
					break;
			}
		}
	
	}

}